﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Windows.Forms;
using RibbonEditor.AppCode;

namespace RibbonEditor.CommandUIDefinitionClasses
{
    public class ToggleButton : ICommandUIDefinition, IControlsChild, IXmlBuildable
    {
        public string Alt { get; set; }
        public string Command { get; set; }
        public string CommandValueId { get; set; }
        public string Description { get; set; }
        public string Id { get; set; }
        public string Image16by16 { get; set; }
        public string Image16by16Class { get; set; }
        public int? Image16by16Left { get; set; }
        public int? Image16by16Top { get; set; }
        public string Image32by32 { get; set; }
        public string Image32by32Class { get; set; }
        public int? Image32by32Left { get; set; }
        public int? Image32by32Top { get; set; }
        public string LabelCss { get; set; }
        public string LabelText { get; set; }
        public string MenuItemId { get; set; }
        public string QueryCommand { get; set; }
        public int? Sequence { get; set; }
        public string TemplateAlias { get; set; }
        public string ToolTipDescription { get; set; }
        public string ToolTipHelpKeyWord { get; set; }
        public string ToolTipImage32by32 { get; set; }
        public string ToolTipImage32by32Class { get; set; }
        public int? ToolTipImage32by32Left { get; set; }
        public int? ToolTipImage32by32Top { get; set; }
        public string ToolTipShortcutKey { get; set; }
        public string ToolTipTitle { get; set; }

        public ToggleButton()
        { }

        public ToggleButton(XmlNode node)
        {
            try
            {
                this.Alt = XmlHelper.GetAttribute(node, "Alt");
                this.Command = XmlHelper.GetAttribute(node, "Command");
                this.CommandValueId = XmlHelper.GetAttribute(node, "CommandValueId");
                this.Description = XmlHelper.GetAttribute(node, "Description");
                this.Id = XmlHelper.GetAttribute(node, "Id");
                this.Image16by16 = XmlHelper.GetAttribute(node, "Image16by16");
                this.Image16by16Class = XmlHelper.GetAttribute(node, "Image16by16Class");
                this.Image16by16Left = XmlHelper.GetNullableIntAttribute(node, "Image16by16Left");
                this.Image16by16Top = XmlHelper.GetNullableIntAttribute(node, "Image16by16Top");
                this.Image32by32 = XmlHelper.GetAttribute(node, "Image32by32");
                this.Image32by32Class = XmlHelper.GetAttribute(node, "Image32by32Class");
                this.Image32by32Left = XmlHelper.GetNullableIntAttribute(node, "Image32by32Left");
                this.Image32by32Top = XmlHelper.GetNullableIntAttribute(node, "Image32by32Top");
                this.LabelCss = XmlHelper.GetAttribute(node, "LabelCss");
                this.LabelText = XmlHelper.GetAttribute(node, "LabelText");
                this.MenuItemId = XmlHelper.GetAttribute(node, "MenuItemId");
                this.QueryCommand = XmlHelper.GetAttribute(node, "QueryCommand");
                this.Sequence = XmlHelper.GetNullableIntAttribute(node, "Sequence");
                this.TemplateAlias = XmlHelper.GetAttribute(node, "TemplateAlias");
                this.ToolTipDescription = XmlHelper.GetAttribute(node, "ToolTipDescription");
                this.ToolTipHelpKeyWord = XmlHelper.GetAttribute(node, "ToolTipHelpKeyWord");
                this.ToolTipImage32by32 = XmlHelper.GetAttribute(node, "ToolTipImage32by32");
                this.ToolTipImage32by32Class = XmlHelper.GetAttribute(node, "ToolTipImage32by32Class");
                this.ToolTipImage32by32Left = XmlHelper.GetNullableIntAttribute(node, "ToolTipImage32by32Left");
                this.ToolTipImage32by32Top = XmlHelper.GetNullableIntAttribute(node, "ToolTipImage32by32Top");
                this.ToolTipShortcutKey = XmlHelper.GetAttribute(node, "ToolTipShortcutKey");
                this.ToolTipTitle = XmlHelper.GetAttribute(node, "ToolTipTitle");
            }
            catch (Exception error)
            {
                MessageBox.Show("An error occured: " + error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        public void AddNode(System.Xml.XmlNode commandUINode)
        {
            try
            {
                XmlNode toggleButtonNode = XmlHelper.AddNode(commandUINode, "ToggleButton");
                XmlHelper.AddAttribute(toggleButtonNode, "Alt", this.Alt);
                XmlHelper.AddAttribute(toggleButtonNode, "Command", this.Command);
                XmlHelper.AddAttribute(toggleButtonNode, "CommandValueId", this.CommandValueId);
                XmlHelper.AddAttribute(toggleButtonNode, "Description", this.Description);
                XmlHelper.AddAttribute(toggleButtonNode, "Id", this.Id);
                XmlHelper.AddAttribute(toggleButtonNode, "Image16by16", this.Image16by16);
                XmlHelper.AddAttribute(toggleButtonNode, "Image16by16Class", this.Image16by16Class);
                XmlHelper.AddAttribute(toggleButtonNode, "Image16by16Left", this.Image16by16Left);
                XmlHelper.AddAttribute(toggleButtonNode, "Image16by16Top", this.Image16by16Top);
                XmlHelper.AddAttribute(toggleButtonNode, "Image32by32", this.Image32by32);
                XmlHelper.AddAttribute(toggleButtonNode, "Image32by32Class", this.Image32by32Class);
                XmlHelper.AddAttribute(toggleButtonNode, "Image32by32Left", this.Image32by32Left);
                XmlHelper.AddAttribute(toggleButtonNode, "Image32by32Top", this.Image32by32Top);
                XmlHelper.AddAttribute(toggleButtonNode, "LabelCss", this.LabelCss);
                XmlHelper.AddAttribute(toggleButtonNode, "LabelText", this.LabelText);
                XmlHelper.AddAttribute(toggleButtonNode, "MenuItemId", this.MenuItemId);
                XmlHelper.AddAttribute(toggleButtonNode, "CommandType", this.QueryCommand);
                XmlHelper.AddAttribute(toggleButtonNode, "Sequence", this.Sequence);
                XmlHelper.AddAttribute(toggleButtonNode, "TemplateAlias", this.TemplateAlias);
                XmlHelper.AddAttribute(toggleButtonNode, "ToolTipDescription", this.ToolTipDescription);
                XmlHelper.AddAttribute(toggleButtonNode, "ToolTipHelpKeyWord", this.ToolTipHelpKeyWord);
                XmlHelper.AddAttribute(toggleButtonNode, "ToolTipImage32by32", this.ToolTipImage32by32);
                XmlHelper.AddAttribute(toggleButtonNode, "ToolTipImage32by32Class", this.ToolTipImage32by32Class);
                XmlHelper.AddAttribute(toggleButtonNode, "ToolTipImage32by32Left", this.ToolTipImage32by32Left);
                XmlHelper.AddAttribute(toggleButtonNode, "ToolTipImage32by32Top", this.ToolTipImage32by32Top);
                XmlHelper.AddAttribute(toggleButtonNode, "ToolTipShortcutKey", this.ToolTipShortcutKey);
                XmlHelper.AddAttribute(toggleButtonNode, "ToolTipTitle", this.ToolTipTitle);
            }
            catch (Exception error)
            {
                MessageBox.Show("An error occured: " + error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        public void BuildTreeViewElement(TreeNode parentNode)
        {
            try
            {
                TreeNode node = new TreeNode("ToggleButton");
                node.Tag = this;
                node.ContextMenuStrip = ContextMenuStripHelper.BuildUICommandDefContextMenuStrip(node, null, true);

                parentNode.Nodes.Add(node);
            }
            catch (Exception error)
            {
                MessageBox.Show("An error occured: " + error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
